{template 'header'}
<style type="text/css">
.book-exam-page .result-word-one {
    font-size:23px;
    margin-bottom:10px;
    font-weight:bold;
}
.book-exam-page .result-p {
    margin:0 50px;
    text-align:justify;
}
.book-exam-page .result-word {
    top:42%;
    text-align:center;
    -webkit-letter-spacing:1px;
    -moz-letter-spacing:1px;
    -ms-letter-spacing:1px;
    letter-spacing:1px;
    font-size:16px;
}
.book-exam-page .result-word span {
    color:#fff95f;
    font-weight:bold;
    -webkit-letter-spacing:1px;
    -moz-letter-spacing:1px;
    -ms-letter-spacing:1px;
    letter-spacing:1px;
}
.book-exam-page .scroll-result {
    position:fixed;
    bottom:2%;
    width:100%;
    left:0;
    text-align:center;
}
@media(max-width:350px) {
    .book-exam-page .medal {
        -webkit-transform:scale(.9) transform-origin:50% 50%;
        -ms-transform:scale(.9) transform-origin:50% 50%;
        transform:scale(.9) transform-origin:50% 50%;
    }
    .book-exam-page .medal .result-word {
        top:38%;
    }
    .book-exam-page .scroll-result {
        -webkit-transform:scale(.8) transform-origin:50% 100%;
        -ms-transform:scale(.8) transform-origin:50% 100%;
        transform:scale(.8) transform-origin:50% 100%;
    }
    .book-exam-page .result-p {
        margin:0 45px;
    }
}
.book-exam-page .progress {
    display:-webkit-box;
    display:-webkit-flex;
    display:-ms-flexbox;
    display:flex;
    margin:21px 0;
    margin-top:30px;
}
.book-exam-page .progress span {
    display:block;
    height:14px;
    width:14px;
    text-align:center;
    color:#fe5365;
    font-weight:600;
}
.book-exam-page .progress .schedule-wrap {
    position:relative;
    margin:3px 4px;
    height:8px;
    -webkit-flex:1;
    -ms-flex:1;
    flex:1;
    background-color:#fff;
    border-radius:20px;
}
.book-exam-page .progress .schedule-wrap .schedule-bar {
    -webkit-transition 0.3s all position:absolute;
    transition 0.3s all position:absolute;
    left:0;
    right:0;
    width:60%;
    height:100%;
    border-radius:20px;
    background:-webkit-linear-gradient(left, #fe956f, #fe5064);
}
.book-exam-page .schedule {
    right:-47px;
    top:0;
    width:135px;
    padding-top:15px;
    -webkit-animation:read-page-schedule 1s 1s 1;
    animation:read-page-schedule 1s 1s 1;
    -webkit-transition:all 1s;
    transition:all 1s;
}
.book-exam-page .schedule-gif {
    position:fixed;
    width:100%;
    top:0;
    max-width:480px;
    left:0;
    right:0;
    margin:auto;
    z-index:1;
}
.book-exam-page .schedule-gif img {
    width:60px;
    position:absolute;
    right:15px;
    top:30px;
}
.book-exam-page .card {
    background-color:#fff;
    border-radius:10px;
    box-shadow:0 0 33px -13px #c3c3c3;
    padding:13px 21px 0 21px;
    -webkit-letter-spacing:1px;
    -moz-letter-spacing:1px;
    -ms-letter-spacing:1px;
    letter-spacing:1px;
}
.book-exam-page .card.is-left, .book-exam-page .card.is-right {
    position:fixed;
    left:-60px;
    top:35px;
    height:calc(100vh - 110px);
}
.book-exam-page .card.is-right {
    right:-60px;
    left:auto;
}
.book-exam-page .pagination {
    height:60px;
    margin:auto;
    font-size:18px;
    text-align:center;
    position:relative;
    color:#666;
    border-top:1px solid #f1f1f1;
    margin-top:15px;
}
.book-exam-page .pagination .next, .book-exam-page .pagination .pre {
    padding:3px 9px;
    border-radius:15px;
    width:65px;
}
.book-exam-page .pagination .pre {
    border:1px #b5b5b5 solid;
    background:#fff;
    color:#b5b5b5;
}
.book-exam-page .title {
    font-size:16px;
    margin-bottom:15px;
    padding-bottom:15px;
    color:#fe5264;
    border-bottom:1px solid #f1f1f1;
}
.book-exam-page .options .option-item, .book-exam-page .results .option-item {
    display:-webkit-box;
    display:-webkit-flex;
    display:-ms-flexbox;
    display:flex;
    padding:11px 8px;
    margin-bottom:3px;
}
.book-exam-page .options .option-item.active, .book-exam-page .results .option-item.active {
    background:#ffe4e6;
}
.book-exam-page .options .option-item .radio, .book-exam-page .results .option-item .radio {
    width:14px;
    height:14px;
    border:solid 1px #868686;
    border-radius:100%;
    margin-right:10px;
    margin-top:2px;
}
.book-exam-page .options .option-item.active .radio, .book-exam-page .results .option-item.active .radio {
    border:1px solid #fb4a62;
    position:relative;
}
.book-exam-page .options .option-item.active .radio::after, .book-exam-page .results .option-item.active .radio::after {
    content:' ' position:absolute;
    width:8px;
    height:8px;
    border-radius:100%;
    background:-webkit-linear-gradient(left, #fe956f, #fe5064) top:2px;
    left:2px;
}
.book-exam-page .options .option-item.active .text, .book-exam-page .results .option-item.active .text {
    color:#fe5264;
}
.book-exam-page .options .option-item.success .radio, .book-exam-page .results .option-item.success .radio {
    background-image:url(https://daka666-1253442168.file.myqcloud.com/college_pro_media/tool/files/20190125_171924_right.png) !important;
    background-size:contain;
    border:none;
}
.book-exam-page .options .option-item.error .radio, .book-exam-page .results .option-item.error .radio {
    background-image:url(https://daka666-1253442168.file.myqcloud.com/college_pro_media/tool/files/20190125_164609_error.png);
    background-size:contain;
    border:none;
}
.book-exam-page .options .option-item .text, .book-exam-page .results .option-item .text {
    font-size:14px;
    line-height:1.3;
    color:#666;
    -webkit-flex:1;
    -ms-flex:1;
    flex:1;
}
.book-exam-page.result .card {
    min-height:calc(100vh - 70px);
    height:auto;
}
.book-exam-page.result .result-title {
    font-size:23px;
}
.book-exam-page.result .sub-result-title {
    font-size:17px;
    color:#999;
    margin-bottom:15px;
}
.book-exam-page.result .intro {
    font-size:14px;
    color:#999;
    padding:23px 0;
    line-height:1.7;
    text-align:justify;
}
.book-exam-page.result .results {
    padding-top:23px;
    border-top:1px solid #f9f9f9;
}
</style>
    <div class="book-exam-page result">
        <div style="width: 100%;display: none;">
            <img id="book-exam-res" src="" alt="" style="width: 100%;">
        </div>
        <div class="card" style="margin: 15px;">
            <div class="g-text-center">
                <div class="result-title g-margin-b">再接再厉 继续学习</div>
                <div class="sub-result-title">（红色为所选的错误答案，绿色为正确答案）</div>
            </div>
            <div class="results">
            </div>
        </div>
        <div onclick="location.href='{php echo $this->murl('bremark');}'" class="schedule g-fixed g-img-full">
            <div class="schedule g-fixed g-img-full">
                <img src="{RES}img/bremark_1.png" alt="">
            </div>
        </div>
        <div class="anm-slide-down-fade" style="width: 100%; height: 40px; font-size: 16px; text-align: center; position: fixed; bottom: 0px; line-height: 40px; max-width: 480px; background-color: rgb(244, 165, 0); color: rgb(255, 255, 255);">上滑查看测试答案</div>
        <div class="g-modal  g-hidden">
            <div class="g-mask"></div>
            <div class="dialog">
                <div class="content">
                    <div class="modal-body">
                        <img src="{RES}img/bremark_fail.png" alt="" style="width: 121px; height: 75.88px; margin-bottom: 17px;">
                        <p style="font-size: 0.18rem; margin-left: 1em;">打卡失败！</p>
                        <p class="g-color-grey" style="font-size: 0.14rem; padding-top: 0.05rem;">如需打卡请前往打卡页面</p>
                    </div>
                </div>
                <div class="g-modal-footer"><a class="g-modal-btn grey" href="javascript:;">取消</a><a class="g-modal-btn active" href="javascript:;">立即打卡</a>
                </div>
            </div>
        </div>
    </div>
<canvas id="myCanvas" width="640" height="1008" style="display:none;"></canvas>    
{template 'loading'}
<script>  
var mem_book_id = getCookie('mem_book');
function getInfo(){
	$.ajax({
		url:'{php echo $this->murl("bresult",["did"=>$_GPC["did"]])}',
		data: {bid: mem_book_id},
		type: "post",
		success: function(dat){
			dat = JSON.parse(dat);
			console.log(dat);
			if(dat.code==1){
				if(dat.poster.id > 0) createPoster(dat.poster)
				var str = '';
				for(var i in dat.question){
					var i_index = i+1;
					str += '<div class="result">';
					str += '<div class="title">'+i_index+'.'+dat.question[i].title+'</div>';
					str += '<div class="options">';
					var detail = dat.question[i].detail
					for(var j in detail){
						var suc_str = '';
						var err_str = '';
						if(detail[j].issure==1) suc_str = 'success';
						else{
							if(dat.question[i].a_status == j) err_str = 'error';
						}
						str += '<div class="option-item '+err_str+' '+suc_str+'">'
						str += '<div class="radio"></div>'
						str += '<div class="text">'+detail[j].title+'</div>'
						str += '</div>'
					}
					str += '</div>';
					if(dat.question[i].remark && dat.question[i].remark!='') str += '<div class="intro">'+dat.question[i].remark+'</div>';
					str += '</div>';
				}
				$('.results').append(str);
			}
			else{
				msgTip(dat.msg,function(){
					location.href='{php echo $this->murl("index")}'
				})
			}
		}
	});
} 
var nickname = '{$mem["nickname"]}'
function createPoster(poster){
	sysPoster = poster.poster.data;
	var avatar_pic = new Image();
	avatar_pic.src = '{$mem["avatar"]}';
	avatar_pic.onload = function(e) {
		var qr_pic = new Image();
		qr_pic.src = poster.qurl;
		qr_pic.onload = function(e) {
			var canvas = document.getElementById("myCanvas");
			var cxt = canvas.getContext("2d");
			
			var bg_pic = new Image();
			bg_pic.src = poster.poster.bg;
			bg_pic.onload = function(e) {
				cxt.drawImage(bg_pic, 0, 0, 640, 1008);
				for(var ii in sysPoster){
					var pData = sysPoster[ii];
					pData.left = pData.left.replace('px', '');
			  		pData.top = pData.top.replace('px', '');
			      	pData.width = pData.width.replace('px', '');
			      	pData.height = pData.height.replace('px', '');
			      	pData.left = parseFloat(pData.left) * 2;
			      	pData.top = parseFloat(pData.top) * 2;
			      	pData.width = parseFloat(pData.width) * 2;
			      	pData.height = parseFloat(pData.height) * 2;
			      	if(pData.size) {
			      		pData.size = pData.size.replace('px', '');
			      		pData.size = parseFloat(pData.size) * 2;
			      	}
			      	if(pData.type=='img'){
						cxt.drawImage(avatar_pic, pData.left, pData.top, pData.width, pData.height);
					}
					else if(pData.type=='qr'){
						cxt.drawImage(qr_pic, pData.left, pData.top, pData.width, pData.height);
					}
					else if(pData.type=='name'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(nickname, pData.left, trueTop);
					}
					else if(pData.type=='score'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.score, pData.left, trueTop);
					}
					else if(pData.type=='book'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.btitle, pData.left, trueTop);
					}
					else if(pData.type=='dict'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.dtitle, pData.left, trueTop);
					}
					else if(pData.type=='yeah'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.num, pData.left, trueTop);
					}
					else if(pData.type=='mrate'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.rate+'%', pData.left, trueTop);
					}
				}
				var u = navigator.userAgent, app = navigator.appVersion;
		    	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
		    	var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
		    	if(isIOS){
		    		var src = canvas.toDataURL().replace("data:image/png;base64,","");
		    	}
		    	isAndroid = true;
		    	if(isAndroid){
		    		var src = canvas.toDataURL("image/png");
		    	}
		    	$('#book-exam-res').attr('src', src);
		    	$('#book-exam-res').parent('div').show();
			}
		}
	}	
}
$(function(){
	getInfo();
})
</script>    
</body></html>